package com.zealcomm.ivcsagent.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.RelativeLayout
import com.zealcomm.ivcscustomer.R
import org.webrtc.EglBase
import org.webrtc.RendererCommon
import org.webrtc.RendererCommon.RendererEvents
import org.webrtc.SurfaceViewRenderer

class RemoteVideoView : RelativeLayout {

    var svrAgent: SurfaceViewRenderer
    private var ivChangeAI: ImageView
    private var ivAudio:ImageView
    constructor(context: Context) : this(context, null)
    constructor(context: Context, attributeSet: AttributeSet?) : this(context, attributeSet, 0)
    constructor(context: Context, attributeSet: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attributeSet,
        defStyleAttr
    ) {
        LayoutInflater.from(context).inflate(R.layout.view_remote_video, this, true)
        svrAgent = findViewById(R.id.svr_agent)
        svrAgent.setEnableHardwareScaler(false)
        svrAgent.setZOrderMediaOverlay(false)
        svrAgent.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT)

        ivChangeAI = findViewById(R.id.iv_change_ai)
        ivAudio = findViewById(R.id.iv_audio)
    }

    fun init(sharedContext: EglBase.Context, rendererEvents: RendererEvents?) {
        svrAgent.init(sharedContext, rendererEvents)
    }

    fun isChangingAI(show: Boolean) {
        ivChangeAI.visibility = if (show) {
            View.VISIBLE
        } else {
            View.GONE
        }
    }

    fun isOnlyAudio(onlyAudio: Boolean){
        ivAudio.visibility = if (onlyAudio){
            View.VISIBLE
        }else{
            View.GONE
        }
    }
}